package com.whfc.ms.api.sys.controller;

import com.alibaba.fastjson.JSON;
import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.dto.SysRuleDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.param.SysRuleFastAdd;
import com.whfc.ms.api.sys.service.MsSysRuleFastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/ms/api/userRuleFast")
public class SysUserRoleFastController extends BaseController {

    @Autowired
    private MsSysRuleFastService msSysRuleFastService;


    @GetMapping(value = "/getRuleFastByDeptId")
    public Result getRuleFastByDeptId(@SessionAttribute(SessionAttr.MS_USER) SysUser loginUser,
                       @RequestParam(value = "deptId", required = false) Integer deptId) {
        logger.info("获取当前用户快捷菜单，loginUser:{},deptId:{}", loginUser.getUsername(), deptId);
        List<SysRuleDTO> byUserIdAndDeptId = msSysRuleFastService.findByUserIdAndDeptId(loginUser.getId(), deptId);
        return ResultUtil.success(byUserIdAndDeptId);
    }

    @GetMapping(value = "/getAllRuleByUserId")
    public Result getAllRuleByUserId(@SessionAttribute(SessionAttr.MS_USER) SysUser loginUser,
                       @RequestParam(value = "deptId", required = false) Integer deptId) {
        logger.info("获取当前用户菜单列表，loginUser:{},deptId:{}", loginUser.getUsername(), deptId);
        List<SysRuleDTO> byUserIdAndDeptId = msSysRuleFastService.findAllByUserIdAndDeptId(loginUser.getId(),deptId);
        return ResultUtil.success(byUserIdAndDeptId);
    }

    @PostMapping(value = "/addUserRuleFast")
    public Result addUserRuleFast(@SessionAttribute(SessionAttr.MS_USER) SysUser loginUser,
                                     @RequestBody SysRuleFastAdd ruleFastAdd) {
        logger.info("新增快捷菜单，loginUser:{},ruleFastAdd:{}", loginUser.getUsername(), JSON.toJSONString(ruleFastAdd));
        ruleFastAdd.setUserId(loginUser.getId());
        msSysRuleFastService.addUserRuleFast(ruleFastAdd);
        return ResultUtil.success();
    }

}
